package com.xy.biz.mes.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.mes.domain.bo.ManufactureOrderBO;
import com.xy.biz.mes.domain.po.ManufactureOrderPO;
import com.xy.tool.util.BeanUtilsEx;
import com.xy.biz.mes.domain.query.ManufactureOrderQuery;
import com.xy.biz.mes.domain.resp.GetManufactureOrderResponse;
import com.xy.biz.mes.domain.req.SaveManufactureOrderRequest;
import com.xy.biz.mes.domain.req.ListManufactureOrderRequest;

/**
 *
 *
 * @author zsp
 * @date 2022-1-6
 */
public class ManufactureOrderConverter {

    public static ManufactureOrderPO toPO(ManufactureOrderBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureOrderPO(), true);
    }

    public static List<ManufactureOrderPO> toPO(Collection<ManufactureOrderBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureOrderPO(), true);
    }

    public static ManufactureOrderBO fromPO(ManufactureOrderPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureOrderBO());
    }

    public static List<ManufactureOrderBO> fromPO(Collection<ManufactureOrderPO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureOrderBO());
    }

    public static ManufactureOrderBO toBO(SaveManufactureOrderRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureOrderBO(), (s, t) -> {
            t.setGoodsList(ManufactureOrderGoodsConverter.toBO(s.getGoodsList()));
        });
    }

    public static List<ManufactureOrderBO> toBO(Collection<SaveManufactureOrderRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureOrderBO(), (s, t) -> {
            t.setGoodsList(ManufactureOrderGoodsConverter.toBO(s.getGoodsList()));
        });
    }

    public static GetManufactureOrderResponse toResponse(ManufactureOrderBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetManufactureOrderResponse());
    }

    public static List<GetManufactureOrderResponse> toResponse(Collection<ManufactureOrderBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetManufactureOrderResponse(), (s, t) -> {
            t.setGoodsList(ManufactureOrderGoodsConverter.toResponse(s.getGoodsList()));
        });
    }

    public static ManufactureOrderQuery toQuery(ListManufactureOrderRequest source) {
        if (null == source) {
            return null;
        }
        ManufactureOrderQuery target = new ManufactureOrderQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

}
